<template>
    <div class="article-list" v-if="article.data">
        <div class="item" v-for="(item, index) in article.data" :key="index">
            <div class="left u-img" v-if="item.imgUrl">
                <el-image :src="item.imgUrl" v-show="!isPhone">
                    <div slot="error" class="image-slot">
                        <i class="el-icon-picture-outline"></i>
                    </div>
                </el-image>
                <van-image :src="item.imgUrl" v-show="isPhone">
                    <div slot="error" class="image-slot">
                        <i class="el-icon-picture-outline"></i>
                    </div>
                </van-image>
            </div>
            <div :class="['right-artice', item.imgUrl ? 'right-artice-use-img' : '']">
                <div class="item-title eli1">
                    <a :href="'/details/' + item.ID" >
                        {{ item.title }}
                    </a>
                </div>
                <div class="item-content">
                    <a :href="'/details/' + item.ID" :class="['brfie' , isPhone ? '' : 'eli1']">
                        {{ item.brfie }}
                    </a>
                </div>
                <div class="bottom">
                    <div class="bottom-left" >
                        <div class="read" v-show="!isPhone">阅读量:{{ item.reading }}</div>
                        <div class="like">{{ item.addtime }}</div>
                        <div class="type" v-show="!isPhone">
                            <a :href="'/articles/' + item.typeID">
                                {{ item.typeName }}
                            </a>
                        </div>
                    </div>
                    <div class="bottom-right" v-show="!isPhone">
                        <a :href="'/details/' + item.ID">立即阅读</a>
                    </div>
                    <div class="bottom-left" v-show="isPhone">
                        <div class="read">阅读量:{{ item.reading }}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { isPhone } from '../../utils/index';
export default {
    name: 'ArticleItem',
    props: {
        article: {
            type: Object,
            defalut: () => {
                return {}
            }
        }
    },
    data() {
        return {
            isPhone: false,
        }
    },
    mounted() {
        this.getIsPhone();
    },
    methods: {
        /**获取是否在手机端*/
        async getIsPhone() {
            this.isPhone = await isPhone();
            window.addEventListener('resize', async () => {
                this.isPhone = await isPhone();
                if (!this.isPhone && this.showSearch) {
                    this.cancelSearch()
                }
            });
        },
    }
}
</script>
<style lang="scss" scoped>
.article-list {
    .item-empty {
        text-align: center;
        padding: 20px;
        font-size: 20px;
        color: var(--fontColor);
    }
    .item {
        width: 100%;
        background-color: #fff;
        border: #fff;
        margin: 0 auto 20px;
        padding: 16px;
        box-shadow: 0 4px 8px 6px rgba(7, 17, 21, 0.06);
        transition: all .3s;
        border-radius: 8px;
        display: flex;
        cursor: pointer;

        &:hover {
            box-shadow: 0 4px 8px 10px rgba(7, 17, 21, 0.1);

            .item-title {
                a {
                    color: skyblue;
                    transition: all 0.3s;
                }
            }
        }

        .left {
            width: 300px;
            height: 150px;
            overflow: hidden;
            margin-right: 20px;
            position: relative;
        }

        /deep/.el-image {
            width: 100%;

            img {
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
        }

        .right-artice {
            width: 100%;

            .item-title {
                font-weight: 600;
                font-size: 20px;
                line-height: 46px;
                transition: all .3s;

                &:hover {
                    color: skyblue;
                }
            }

            .item-content {
                font-size: 14px;
                margin: 20px 0;

                a {
                    display: block;
                    color: #242424;
                    word-break: break-all;
                }
            }

            .bottom {
                display: flex;
                justify-content: space-between;

                .bottom-left {
                    display: flex;
                    color: #999;
                    font-size: 12px;
                    align-items: center;
                }

                .read {
                    padding-right: 10px;
                }

                .time {
                    padding-right: 10px;
                }

                .type {
                    background-color: #e0e0e0;
                    padding: 2px 5px;
                    font-size: 14px;
                    border-radius: 3px;
                    transition: all .3s;
                    margin-left: 5px;

                    &:hover {
                        background-color: #aaa;
                        color: #fff;
                    }

                    a {
                        display: inline-block;
                        width: 100%;
                        height: 100%;
                    }
                }

                .bottom-right {
                    padding: 3px 8px;
                    border-radius: 5px;
                    color: #fff;
                    transition: all .3s;

                    &:hover {
                        background-color: #aaa;
                        color: #fff;
                    }
                }
            }
        }

        .right-artice-use-img {
            width: calc(100% - 300px);
        }
    }

    @media screen and (max-width: 768px) {
        .item {
            display: block;
            .left{
                width: 100%;
            }
            .right-artice{
                width: 100%;
                .item-title{
                    font-size: 16px;
                    line-height: 30px;
                }
                .item-content{
                    margin: 10px 0;
                }
            }
            .right-artice-use-img{
                width: 100%;
            }
        }
    }
}
@media screen and (max-width: 768px) {
    .article-list{
        padding: 10px;
    }
}
</style>